package com.hnchances.controller;

import com.hnchances.domain.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisClientConfig;

@RestController
@RequestMapping(path = "/captcha")
@Api(tags = "验证码")
@Slf4j
public class CaptchaController {
    @GetMapping("/text")
    @ApiOperation("生成并发送验证码")
    public ResponseResult<String> generateCaptcha(){
        String s = RandomStringUtils.randomNumeric(4);

        JedisClientConfig config = DefaultJedisClientConfig.builder().password("123456").build();
        Jedis jedis = new Jedis("192.168.100.168",6379,config);
        jedis.set("captcha",s);
        log.info("captcha:{}",s);
        return ResponseResult.ok(s);
    }
}
